package com.caipiao.util.db;

/**
 * @author GaoFeng
 */

public class DBParam
{
	public DBParam(String paramName, DBParamType paramType, DBFieldType filedType, Object object)
	{
		this.paramName = paramName;
		this.paramType = paramType;
		this.fieldType = filedType;
		this.object = object;
	}
	
	String paramName;					//参数名
	DBParamType paramType;		//参数输入输出类型
	DBFieldType fieldType;				//参数域类型
	public Object object;				//输入输出对象
	
	
	public static String Get_Input_Param_Str(DBParam[] param)
	{
		StringBuffer input_param = new StringBuffer();
		input_param.append(" Input [");
		
		try
		{
    		boolean first = true;
    		
    		for(int i = 0; i < param.length; i++)
    		{
    			switch(param[i].paramType)
    			{
    				case pNoUse:
    				case pInput:
    				{
    					if (first)
    					{
    						first = false;
    					}
    					else
    					{
    						input_param.append(", ");
    					}
    					
    					switch(param[i].fieldType)
    					{
    						case pString:
    						{
    							input_param.append(param[i].paramName);
    							input_param.append(":");
    							if (null != param[i].object)
    							{
    								input_param.append((String)param[i].object);
    							}
    							break;
    						}
    						default:
    							break;
    					}
    					break;
    				}
    				default:
    					break;
    			}
    		}
		}
		catch(Exception e)
		{
			return "Get_Input_Param_Str Exception:" + e;
		}
		
		input_param.append("]");
		return input_param.toString();
	}
	
	public static String Get_Output_Param_Str(DBParam[] param)
	{
		StringBuffer output_param = new StringBuffer();
		output_param.append(" Output [");
		
		try
		{	
			boolean first = true;
		
    		for(int i = 0; i < param.length; i++)
    		{
    			switch(param[i].paramType)
    			{
    				case pOutput:
    				{
    					
    					if (first)	//首个
    					{
    						first = false;
    					}
    					else
    					{
    						output_param.append(", ");
    					}
    					
    					switch(param[i].fieldType)
    					{
    						case pString:
    						{
    							output_param.append(param[i].paramName);
    							output_param.append(":");
    							output_param.append(((DBOutString)param[i].object).toString());
    							break;
    						}
    						case pCursor:
    						{
    							output_param.append(param[i].paramName);
    							output_param.append(": Cousor");
    							break;
    						}
    						default:
    							break;
    					}
    					break;
    				}
    				default:
    					break;
    			}
    		}
		}	
    	catch(Exception e)
    	{
    		return "Get_Output_Param_Str Exception:" + e;
    	}
    	
		output_param.append("]");
		return output_param.toString();
	}
	
}

